/*-----------------------------------------------------------------------------
-- Archivo:                         test_alu.c
-- Fecha de creacion:               05/02/2011
-- Ultima fecha de modificacion:    05/02/2011
-- Diseñador:                       Liliana Andrade
-- Diseño:                          test_alu
-- Proposito:                       Generar estimulos de prueba para la ALU
-----------------------------------------------------------------------------*/

#include <stdio.h>
#include "genpat.h"

char* inttostr(int entier) {
    char* str;
    str = (char *) mbkalloc (32 * sizeof(char));
    sprintf(str,"%d",entier);
    return(str);
}

main() {
 
    DEF_GENPAT("test_alu");

    DECLAR("A_i"      ,":2","X", IN , "3 downto 0", "");
    DECLAR("B_i"      ,":2","X", IN , "3 downto 0", "");
    DECLAR("C_i"      ,":2","B", IN , ""          , "");
    DECLAR("CLK"      ,":2","B", IN , ""          , "");
    DECLAR("ALU_OP_i" ,":2","X", IN , "3 downto 0", "");
    DECLAR("ALU_o"    ,":2","X", OUT, "3 downto 0", "");
    DECLAR("C_o"      ,":2","B", OUT, ""          , "");
    DECLAR("N_o"      ,":2","B", OUT, ""          , "");
    DECLAR("OVF_o"    ,":2","B", OUT, ""          , "");
    DECLAR("Z_o"      ,":2","B", OUT, ""          , "");

    DECLAR("vdd"      ,":2","B", IN , ""          , "");
    DECLAR("vss"      ,":2","B", IN , ""          , "");

    LABEL("alu");
  
    SETTUNIT("ns");

    /* Inicializacion */

    /* 1 clock */
    AFFECT("0"  , "A_i"     , "0"   );
    AFFECT("0"  , "B_i"     , "0"   );
    AFFECT("0"  , "C_i"     , "0"   );
    AFFECT("0"  , "CLK"     , "1"   );
    AFFECT("0"  , "ALU_OP_i", "0"   );
    AFFECT("0"  , "vdd"     , "1"   ); 
    AFFECT("0"  , "vss"     , "0"   );
    AFFECT("+25", "CLK"     , "0"   );

    /* 2 clock */
    AFFECT("+0" , "A_i"     , "0xC" ); /* 12 */
    AFFECT("+0" , "B_i"     , "0xA" ); /* 10 */
    AFFECT("+0" , "C_i"     , "0" );
    AFFECT("+0" , "ALU_OP_i", "0x0" );
    AFFECT("+25", "CLK"     , "1"   );
    AFFECT("+25", "CLK"     , "0"   );

    /* 3 clock */
    AFFECT("+25", "CLK"     , "1"   );
    AFFECT("+25", "CLK"     , "0"   ); 

    /* 4 clock */
    AFFECT("+25", "CLK"     , "1"   );
    AFFECT("+0" , "ALU_OP_i", "0x0" );
    AFFECT("+25", "CLK"     , "0"   ); 

    /* 5 clock */
    AFFECT("+25", "CLK"     , "1"   );
    AFFECT("+0" , "C_i"     , "0" ); 
    AFFECT("+0" , "ALU_OP_i", "0x4" ); /* 4 -> and */
    AFFECT("+25", "CLK"     , "0"   );

    /* 6 clock */
    AFFECT("+25", "CLK"     , "1"   );
    AFFECT("+0" , "C_i"     , "1" );
    AFFECT("+0" , "ALU_OP_i", "0x5" ); /* 5 -> or */
    AFFECT("+25", "CLK"     , "0"   );

    /* 7 clock */
    AFFECT("+25", "CLK"     , "1"   );
    AFFECT("+0" , "C_i"     , "0" );
    AFFECT("+0" , "ALU_OP_i", "0x6" ); /* 6 -> xor */
    AFFECT("+25", "CLK"     , "0"   );

    /* 8 clock */
    AFFECT("+25", "CLK"     , "1"   );
    AFFECT("+0" , "C_i"     , "1" );
    AFFECT("+0" , "ALU_OP_i", "0x7" ); /* 7 -> not */
    AFFECT("+25", "CLK"     , "0"   );

    /* 9 clock */
    AFFECT("+25", "CLK"     , "1"   );
    AFFECT("+0" , "C_i"     , "0" );
    AFFECT("+0" , "ALU_OP_i", "0x0" ); /* 0 -> suma */
    AFFECT("+25", "CLK"     , "0"   );

    /* 10 clock */
    AFFECT("+25", "CLK"     , "1"   );
    AFFECT("+0" , "C_i"     , "1"   ); /* acarreo 1 */
    AFFECT("+0" , "ALU_OP_i", "0x1" ); /* 1 -> resta */
    AFFECT("+25", "CLK"     , "0"   );

    /* 11 clock */
    AFFECT("+25", "CLK"     , "1"   );
    AFFECT("+0" , "C_i"     , "0"   );
    AFFECT("+0" , "ALU_OP_i", "0xA" ); /* 10 -> multiplicacion */
    AFFECT("+25", "CLK"     , "0"   );
    
    //                          c_o     n_o     ovf_o     z_o
    // ----------------------------------------------------------
    // AND   --> 1000 = 8        -       1       -         0
    // OR    --> 1110 = E        -       1       -         0
    // XOR   --> 0110 = 6        -       0       -         0
    // NOT   --> 0011 = 3        -       0       -         0
    // SUMA  --> 0110 = 6        1       0       1         0
    // RESTA --> 0010 = 2        0       0       0         0
    // MULT  --> 0000 = 0        -       0       -         1

    SAV_GENPAT();

    exit(0);
}
